package cn.mhome.merchant.framework.shiro;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HTML5LinkFilter implements Filter {

    protected final Logger logger = LoggerFactory.getLogger(HTML5LinkFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest requestHttp = (HttpServletRequest) request;
        HttpServletResponse responseHttp = (HttpServletResponse) response;

        String reqUri = requestHttp.getRequestURI();
        int index = reqUri.indexOf("/view");
        if(index != -1){
            String viewUrl = reqUri.substring(reqUri.indexOf("/view"));
            requestHttp.setAttribute("viewUrl", viewUrl);

            requestHttp.getRequestDispatcher("/WEB-INF/view/index.jsp").forward(request,response);
            return;
        }

        chain.doFilter(requestHttp, responseHttp);
    }

    @Override
    public void destroy() {

    }
}

